﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/MasterHalfColum.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.AdvertiesViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Danh sách quảng cáo  
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContentLeft" runat="server">
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
	<script src="/Scripts/jquery.cookie.js" type="text/javascript"></script>
	<script src="/Scripts/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/demo.js"></script>
    <script type="text/javascript">
        function SaveOrder(dropDownList,id) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;
            commitChange(selects,id);
        }
        function commitChange(values,id) {
            var url = '<%=Url.Action("UdpateSortIndex","AdvertiesMaster")%>' + '/' + id + '/' + values;
            $.getJSON(url,function(result){
            $('#Order'+id).val(result);
            });
    }
    function SaveStatus(dropDownList, id) {
        var selectedReport = dropDownList.options[dropDownList.selectedIndex];
        var selects = selectedReport.value;
        actionChangeStatus(selects, id);
    }
        function actionChangeStatus(values,id) {
            var url = '<%=Url.Action("ChangeStatusAdverties","AdvertiesMaster")%>' + '/' + id + '/' + values;
            $.getJSON(url, function (outStr) {
                $('#statusID' + id).val(outStr);
            });
        }
     </script>
     <% using (Html.BeginForm("ListAdverties", "AdvertiesMaster"))
        {%>
    <div class="box ">
		<h2 class="box-header">	</h2>
		<div class="box-content">
                     
                    <div id="grid">      
                                  <div style="margin: 5px; float:right;"><%= Html.ActionLink("Thêm mới", "AddAdverties", null, new { @Class = "button themed" })%></div>	               
				                <table class="display" >
                                <thead>
					                <tr>
						                                                        					               
						                <th>
							                <a href="#" class="<%= AdvertiesMasterController.GetGridThClass(ViewData, "AdvertiesName") %>" 
										                onclick="<%= AdvertiesMasterController.GetGridThOnClick(ViewData, "AdvertiesName")%>">
								                Tên</a>                                                
                                                 
						                </th>
						
                                        <th>
                                            <a href="#" class="<%= AdvertiesMasterController.GetGridThClass(ViewData, "AdvertiesActive") %>" 
										                onclick="<%= AdvertiesMasterController.GetGridThOnClick(ViewData, "AdvertiesActive")%>">
								                Trạng thái</a> 
                                                 
                                                                                       
                                        </th>                                        
						                										                
                                        <th>
                                              
                                        </th>                                  
                                        <th>
                                              
                                        </th>
                                       
					                </tr>
                                  <%--  <tr>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        
                                        <td >
                                             <%= Html.ActionLink("Thêm mới", "AddAdverties", null, new { @Class = "button themed" })%>
                                        </td>
                                    </tr>--%>
                                    <tr>
                                        <td>
                                            <%=Html.TextBoxFor(m => m.sAdvertiesName, new { @class = "form-field hafl", @maxlength = "100" })%>
                                        </td>
                                        <td>
                                             <%
                                                List<SelectListItem> statusSearch = new List<SelectListItem>();
                                                statusSearch.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "Kích hoạt", Value = "true" },
                                                new SelectListItem{ Text = "Không kích hoạt", Value = "false" }
                                                });
                                                %>

                                                <%=Html.DropDownListFor(m =>m.sAdvertiesActive,statusSearch) %> 
                                        </td>
                                        
                                        <td></td>
                                        <td>
                                            <input type="submit" value="Tìm kiếm" class="button themed"/>
                                        </td>
                                    </tr>
                                </thead>
                                <% if (Model.AdvertiesList.Count() == 0) { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="5">
                                               Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% } else { %>
                                <tbody>
					                <% foreach (var item in Model.AdvertiesList) { %>
				                        
						                <tr>						                
                                            
							                <td>
								                <%= Html.Encode(item.AdvertiesName) %>
							                </td>
                                           														               
											
                                            <td>
                                                
                                                <%
                                                    bool newStatus=false;
                                                    if (item.AdvertiesActive == false)
                                                    {
                                                        newStatus=true;
                                                    }
                                                    else if (item.AdvertiesActive == true)
                                                    {
                                                        newStatus=false;
                                                    }
                                                %>
                                                <%
                                                List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                statusDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=newStatus, Text = "Kích hoạt", Value = "true" },
                                                new SelectListItem{Selected=newStatus, Text = "Không kích hoạt", Value = "false" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("statusID" + item.AdvertiesID, statusDrop, new { onchange = "SaveStatus(this," + item.AdvertiesID+ ")" })%>
                                            </td>

                                             <td>
                                            <%=Html.Encode(item.AdvertiesUrl) %>
                                            </td>

                                             <td>
								                <%= Html.DropDownList("Order" + item.AdvertiesID, (SelectList)ViewData["SetOrder"], new { onchange = "SaveOrder(this,"+item.AdvertiesID+")" })%>
							                </td>
                                                                                       

                                            <td>   
								                <%= Html.ActionLink("Cập nhật", "EditAdverties", new { id = item.AdvertiesID })%>								                
							                </td>
                                            <td>
                                                <%
                                                    string returnUrl = Request.Url.ToString();
                                                 %>
                                                <%= Html.ActionLink("Xóa", "DeleteAdverties", new { id = item.AdvertiesID, returnUrl = returnUrl }, new { onclick = "return confirm('Bạn thực sự muốn xóa:" + item.AdvertiesName + " ?');" })%>
                                            </td>
						                </tr>
                                            <script type="text/javascript">
                                                
                                            </script>
                                            
                                             <script type="text/javascript">
                                                 var selecteds = <%=item.Sort %>;
                                                 var combox = document.getElementById("Order"+<%=item.AdvertiesID%>);
                                                 for (i = 0; i < combox.options.length; i++) {
                                                         if (combox.options[i].value == selecteds) {
                                                             combox.options[i].selected = true;
                                                         }          
                                                 }

                                                </script>
					                <% } %>
					            </tbody>
                                 <% } %>
				                </table>
			                <!-- data -->
                                <% if (Model.AdvertiesList.Count() > 0) { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>
		               
	                </div>  <!-- grid -->	
                
               
	    </div>
	</div>
   
    <% } %>
	
    
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContentRight" runat="server"> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
	<script src="/Scripts/jquery.cookie.js" type="text/javascript"></script>
	<script src="/Scripts/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/demo.js"></script>
   
    <div class="box ">
		<h2 class="box-header">	 </h2>
		<div class="box-content">
			    <%=ViewData["ListAdverties"]%> 
	    </div>
	</div>


    
</asp:Content>
